﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Base3
{
    public partial class FListView : Form
    {
        public FListView()
        {
            InitializeComponent();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            List<Employee> eList = new List<Employee>() {};
            for (int i = 1; i <= 20; i++)
            {
                eList.Add(new Employee()
                {
                    EmployeeName = "员工" + i,
                    IdCard = "15646023100" + i,
                    Tel = "182651300" + i,
                    Pos = "职位" + i,
                    Department = "部门" + i,
                    Gender = (i % 2 == 0) ? "男" : "女",
                    Province = "地区" + i
                });
            }

            this.listView1.Items.Clear();      // 清除所有内容
            // 给ListView绑定数据源
            foreach(var em in eList)
            {
                // 1.创建一个ListViewIterm对象  利用第一列的信息
                ListViewItem lvIterm = new ListViewItem(em.EmployeeName);

                // 2.把ListViewIterm对象添加到ListView中
                this.listView1.Items.Add(lvIterm);

                // 3.给当前ListViewIterm对象添加 子项（其他列）
                lvIterm.SubItems.AddRange(new string[] { em.IdCard, em.Tel, em.Pos, em.Department, 
                               em.Province, em.Gender });  // 这里顺序要和列一致
            }

        }
    }
}
